home *** CD-ROM | disk | FTP | other *** search
/ The Best of MacTutor - S…e Code for Volumes 1 to 5 / The Best of MacTutor - Source Code for Volume 1-5 (Wayzata Technology)(6031)(1990).bin / Source Code / #18 (Mar 87) / Printer LSP sources / DumpTPrintStuff next >
Text File  |  1987-02-13  |  7KB  |  273 lines

  1. UNIT DumpTPrint;
  2.  
  3. INTERFACE
  4.  
  5.     USES
  6.         MacPrint, MyGlobals, StringFormat;
  7.  
  8.     PROCEDURE PrintLine;
  9.     PROCEDURE PrintTab;
  10.     PROCEDURE PrintHex (n : LONGINT;
  11.                                     w : INTEGER);
  12.     PROCEDURE PrintInt (n : LONGINT);
  13.     PROCEDURE PrintString (s : Str255);
  14.     PROCEDURE PrintStrNum (s : Str255;
  15.                                     n : LONGINT);
  16.     PROCEDURE PrintStrHex (s : Str255;
  17.                                     n : LONGINT;
  18.                                     w : INTEGER);
  19.     PROCEDURE DumpEnum (msg : Str255;
  20.                                     val, resid : INTEGER);
  21.     PROCEDURE DumpRect (msg : Str255;
  22.                                     r : Rect);
  23.     PROCEDURE DumpPrInfo (msg : Str255;
  24.                                     prinf : TPrInfo);
  25.     PROCEDURE DumpPrXInfo (msg : Str255;
  26.                                     prxi : TPrXInfo);
  27.     PROCEDURE DumpPrStl (msg : Str255;
  28.                                     ps : TPrStl);
  29.     PROCEDURE DumpPrJob (msg : Str255;
  30.                                     pj : TPrJob);
  31.     PROCEDURE DumpPrintX (msg : Str255;
  32.                                     tpp : TPPrint);
  33.     PROCEDURE DumpPrint (msg : Str255;
  34.                                     hand : THPrint);
  35.  
  36. IMPLEMENTATION
  37.  
  38. {-----------Add a line to document-------------}
  39.     PROCEDURE PrintLine;
  40.         VAR
  41.             p : Ptr;
  42.             c : SignedByte;
  43.     BEGIN        {this adds the line to end of the display}
  44.         p := @linebuff;
  45.         TEInsert(Pointer(ORD4(p) + 1), Length(linebuff), hTE);
  46.         c := Return;
  47.         TEInsert(@c, 1, hTE);    { add CR }
  48.         WITH hTE^^ DO        { Check to see if we're beyond bottom of page }
  49.             IF (lineHeight * nLines) > (viewRect.bottom - viewRect.top) THEN
  50.                 TEScroll(0, -hTE^^.lineHeight, hTE);    { scroll up one line }
  51.         linebuff := '';
  52.     END; {PrintLine}
  53.  
  54. {------------Formatting utilities----------------}
  55.     PROCEDURE PrintTab;
  56.         VAR
  57.             col, nexttab : INTEGER;
  58.     BEGIN        { add spaces to next multiple of 8 }
  59.         col := Length(linebuff);
  60.         nexttab := col - INTEGER(BitAnd(col, 7)) + 8;
  61.         WHILE col < nexttab DO
  62.             BEGIN
  63.                 col := col + 1;
  64.                 IF col < 255 THEN
  65.                     insert(' ', linebuff, col);
  66.             END;
  67.     END;
  68.  
  69.     PROCEDURE PrintHex; {(n : LONGINT; w : INTEGER );}
  70.     BEGIN
  71.         SWriteHex(linebuff, n, w);    { actual width }
  72.     END;
  73.  
  74.     PROCEDURE PrintInt; {(n : LONGINT);}
  75.     BEGIN
  76.         SWriteInt(linebuff, n, 0);    { minimum width }
  77.     END;
  78.  
  79.     PROCEDURE PrintString; {(s : Str255);}
  80.     BEGIN
  81.         SWriteString(linebuff, s);
  82.     END;
  83.  
  84.     PROCEDURE PrintStrNum; {(s : Str255; n : LONGINT );}
  85.  
  86.     BEGIN                { format a string and integer }
  87.         PrintTab;
  88.         SWriteString(linebuff, s);
  89.         SWriteInt(linebuff, n, 0);    { minimum width }
  90.     END;
  91.  
  92.     PROCEDURE PrintStrHex; {(s : Str255;n : LONGINT;w : INTEGER);}
  93.     BEGIN                { format a string and hex }
  94.         PrintTab;
  95.         SWriteString(linebuff, s);
  96.         SWriteHex(linebuff, n, w);
  97.     END;
  98.  
  99. { ------------- Format enumeration ------------ }
  100.     PROCEDURE DumpEnum; {(msg : Str255; val, resid : INTEGER);}
  101.         VAR
  102.             s : Str255;
  103.             rh : Handle;
  104.             limitp : WordPtr;
  105.             err : boolean;
  106.     BEGIN
  107.         err := TRUE;
  108.         PrintTab;
  109.         PrintString(msg);
  110.         rh := GetResource('STR#', resid);
  111.         IF (rh <> NIL) THEN        { if we screwed up, don't try to format }
  112.             BEGIN
  113.                 limitp := WordPtr(rh^);    { number of strings }
  114.                 IF (val >= 0) AND (val < limitp^) THEN
  115.                     BEGIN        { in range defined }
  116.                         GetIndString(s, resid, val + 1);
  117.                         PrintString(s);
  118.                         err := FALSE;
  119.                     END
  120.             END;
  121.         IF err THEN
  122.             PrintInt(val);        { no string, show the integer }
  123.     END;
  124.  
  125. { --------------- Format Rect ------------- }
  126.     PROCEDURE DumpRect; {(msg : Str255; r : Rect);}
  127.     BEGIN
  128.         PrintString(msg);
  129.         PrintString(': {');
  130.         PrintInt(r.top);
  131.         PrintString(', ');
  132.         PrintInt(r.left);
  133.         PrintString(', ');
  134.         PrintInt(r.bottom);
  135.         PrintString(', ');
  136.         PrintInt(r.right);
  137.         PrintString('}');
  138.         PrintLine;
  139.     END;
  140.  
  141. { -------------- Format TPrInfo ----------- }
  142.     PROCEDURE DumpPrInfo; {(msg : Str255; prinf : TPrInfo);}
  143.     BEGIN
  144.         PrintString(msg);
  145.         PrintStrNum('iDev: ', prinf.iDev);
  146.         PrintStrNum('iVRes: ', prinf.iVRes);
  147.         PrintStrNum('iHRes: ', prinf.iHRes);
  148.         PrintLine;
  149.         DumpRect('rPage', prinf.rPage);
  150.     END;
  151.  
  152. { ------------- Format TPrXInfo ------------- }
  153.     PROCEDURE DumpPrXInfo; {(msg : Str255; prxi : TPrXInfo);}
  154.     BEGIN
  155.         PrintString(msg);
  156.         PrintStrNum('iRowBytes: ', prxi.iRowBytes);
  157.         PrintStrNum('iBandH: ', prxi.iBandV);
  158.         PrintStrNum('iBandV: ', prxi.iBandH);
  159.         PrintLine;
  160.         PrintStrNum('iDevBytes: ', prxi.iDevBytes);
  161.         PrintStrNum('iBands: ', prxi.iBands);
  162.         PrintLine;
  163.         PrintStrNum('bPatScale: ', prxi.bPatScale);
  164.         PrintStrNum('bUlThick: ', prxi.bUlThick);
  165.         PrintStrNum('bUlOffset: ', prxi.bUlOffset);
  166.         PrintStrNum('bUlShadow: ', prxi.bUlShadow);
  167.         PrintLine;
  168.  
  169.         DumpEnum('scan: ', ORD(prxi.scan), STRN_scan);
  170.  
  171.         PrintStrNum('bXInfoX: ', prxi.bXInfoX);
  172.         PrintLine;
  173.     END;
  174.  
  175. { ------------- Format TPrStl ------------ }
  176.     PROCEDURE DumpPrStl; {( msg : Str255;ps : TPrStl);}
  177.     BEGIN
  178.         PrintString(msg);
  179.         PrintStrHex('wDev: $', ps.wDev, 4);
  180.         DumpEnum('(', BitShift(ps.wDev, -8), STRN_wdev);{device code}
  181.         PrintString(')');
  182.         PrintLine;
  183.  
  184.         PrintStrNum('iPageV: ', ps.iPageV);
  185.         PrintStrNum('iPageH: ', ps.iPageH);
  186.         PrintStrNum('bPort: ', ps.bPort);
  187.  
  188.         DumpEnum('feed: ', ORD(ps.feed), STRN_feed);
  189.  
  190.         PrintLine;
  191.     END;
  192.  
  193. { ------------- Format TPrJob ------------- }
  194.     PROCEDURE DumpPrJob; {(msg : Str255; pj : TPrJob);}
  195.     BEGIN
  196.         PrintString(msg);
  197.         PrintStrNum('iFstPage: ', pj.iFstPage);
  198.         PrintStrNum('iLstPage: ', pj.iLstPage);
  199.         PrintStrNum('iCopies: ', pj.iCopies);
  200.  
  201.         DumpEnum('bJDocLoop: ', ORD(pj.bJDocLoop), STRN_job);
  202.         PrintLine;
  203.  
  204.         DumpEnum('fFromUsr: ', ORD(pj.fFromUsr), STRN_bool);
  205.  
  206.         PrintStrHex('pIdleProc: ', ORD4(pj.pIdleProc), 8);
  207.         PrintStrHex('pFileName ', ORD4(pj.pFileName), 8);
  208.         PrintLine;
  209.  
  210.         PrintStrNum('iFileVol: ', pj.iFileVol);
  211.         PrintStrNum('pFileVers: ', pj.bFileVers);
  212.         PrintStrNum('bJobX: ', pj.bJobX);
  213.         PrintLine;
  214.     END;
  215.  
  216. { ------------ Format printX Array ---------- }
  217.     PROCEDURE DumpPrintX; {( msg : Str255;tpp : TPPrin    );}
  218.         VAR
  219.             i, max : INTEGER;
  220.     BEGIN { Outputs non-zero values, if any; ignore trailing run of zero}
  221.         max := 0;
  222.         FOR i := 1 TO 19 DO
  223.             IF (tpp^.printX[i] <> 0) THEN
  224.                 max := i;         { ignore trailing zeroes }
  225.  
  226.         IF (max > 0) THEN
  227.             BEGIN
  228.                 PrintString(msg);
  229.                 FOR i := 1 TO max DO
  230.                     BEGIN
  231.                         PrintStrNum('[', i);
  232.                         PrintString(']: ');
  233.                         PrintHex(tpp^.printX[i], 4);
  234.                         IF (((i MOD 4) = 0) OR (i = max)) THEN
  235.                             PrintLine;     { every 4th or last one }
  236.                     END
  237.             END
  238.     END;
  239.  
  240. { -------------- Format TPrint ------------ }
  241.     PROCEDURE DumpPrint; {(msg : Str255;hand : THPrint);}
  242.         VAR
  243.             tpp : TPPrint;
  244.             i : INTEGER;
  245.     BEGIN
  246.         HLock(Handle(hand));
  247.         tpp := hand^; { pointer to a TPrint }
  248.  
  249.         PrintLine;
  250.         PrintString(msg);
  251.         PrintLine;
  252.         FOR i := 1 TO Length(msg) DO
  253.             PrintString('-');
  254.         PrintLine;
  255.  
  256.         PrintString('iPrVersion: ');
  257.         PrintInt(tpp^.iPrVersion);
  258.         PrintLine;
  259.  
  260.         DumpPrInfo('prInfo', tpp^.prInfo);
  261.         DumpRect('rPaper', tpp^.rPaper);
  262.         DumpPrStl('prStl', tpp^.prStl);
  263.         DumpPrInfo('prInfoPT', tpp^.prInfoPT);
  264.         DumpPrXInfo('prXInfo', tpp^.prXInfo);
  265.         DumpPrJob('prJob', tpp^.prJob);
  266.         DumpPrintX('printX', tpp);
  267.         PrintString('------------------------------------------------------------------------------');
  268.         PrintLine;
  269.  
  270.         HUnLock(Handle(hand));
  271.     END; {DumpPrint}
  272.  
  273. END.